package com.his.controller;

import com.his.annotation.RequireRoles;
import com.his.common.Const;
import com.his.common.PageParam;
import com.his.common.Rsp;
import com.his.entity.Ward;
import com.his.service.WardService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * (Ward)表控制层
 *
 * @author makejava
 * @since 2020-10-23 18:15:13
 */
@Validated
@RestController
@RequestMapping("ward")
public class WardController {
    /**
     * 服务对象
     */
    @Resource
    private WardService wardService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Ward selectOne(Integer id) {
        return this.wardService.queryById(id);
    }


    /**
     * 查询所有病房
     *
     * @param token
     * @param pageParam2
     * @return
     */
    @RequireRoles(roles = {"nurse", "admin"}, index = 0)
    @PostMapping("selectAll")
    public Rsp selectAll(@RequestHeader(Const.TOKEN) String token, @RequestBody PageParam<Ward> pageParam2) {
        System.out.println(pageParam2.getModel() + "--------------");
        return Rsp.success(wardService.queryAll(pageParam2));
    }

    /**
     * 更新病房信息
     *
     * @param token
     * @param ward
     * @return
     */
    @RequireRoles(roles = {"nurse"}, index = 0)
    @PostMapping("updateOne")
    public Rsp updateOne(@RequestHeader(Const.TOKEN) String token, @Validated(Const.Update.class) @RequestBody Ward ward) {
        return Rsp.success(wardService.update(ward));
    }

    /**
     * 添加病房信息
     *
     * @param token
     * @param ward
     * @return
     */
    @RequireRoles(roles = {"nurse"}, index = 0)
    @PostMapping("insertOne")
    public Rsp insertOne(@RequestHeader(Const.TOKEN) String token, @Validated @RequestBody Ward ward) {
        return Rsp.success(wardService.insert(ward));
    }


    @RequireRoles(roles = {"nurse"}, index = 0)
    @GetMapping ("selectAllByDepId")
    public Rsp selectAllByDepId(@RequestHeader(Const.TOKEN) String token, @NotBlank String depId)
    {
        return Rsp.success(wardService.selectAllByDepId(depId));
    }


}
